package bd403.UIComponents;

import java.util.ArrayList;

import bd403.Backend.Help;
import bd403.namespace.BDActivity;
import bd403.namespace.R;
import bd403.utils.HelpAdapter;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

/* UI and functionality for the viewing a list of help topics of the BrewDawg application.
 * Main author: Brendan & Cody
 */

public class HelpActiv extends ListActivity {
	private ArrayList<String> m_orders;
	private HelpAdapter m_adapter;
	
	/* Initializes the Help Activity UI */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setup();
	}
	
	/* Setup the XML layout, UI of the help page.
	 */
	private void setup() {
		setContentView(R.layout.help);
		m_orders = null;
		
		initializeHelpPage();
	}
	
	/* Initializes the UI components for the help page.
	 */
	private void initializeHelpPage() {
		Help h = BDActivity.getHelp();
		m_orders = h.getTopics();		
		this.m_adapter = new HelpAdapter(this, R.layout.helpitem, m_orders);
		setListAdapter(this.m_adapter);
		
		// Set background color values
		setViewSettings();
	}
	
	/* Sets up the background colors and keyboard functionality for the Help Page */
	private void setViewSettings() {
		ListView lv = getListView();

		lv.setBackgroundColor(Color.BLACK); 
		lv.setCacheColorHint(Color.BLACK);
		lv.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				onClick(view, position, id);
			}	
		});
	}
	
	/* Sets up the function for the on-click of a specific topic. */
    protected void onClick(View v, int position, long id) {
        Intent i = new Intent(this, HelpViewActiv.class);
        
        Help h = BDActivity.getHelp();
        h.setCurrent(position);
//        Toast.makeText(getApplicationContext(), "Position: " + position, Toast.LENGTH_SHORT).show();
        startActivity(i);
    }
    
    /* Resets the Help page on a resume.
     */
    protected void onResume() {
    	super.onResume();
		setup();
    }
}
